<template>
  <div class="box">
    <div class="back" @click="toBack">
      <img src="@/assets/image/return.png" alt="">
    </div>
    <div class="container">
      <div class="loginPic">
        <img src="../../assets/image/login.jpg" alt="" /><br />
        <button @click="toShow1()">点我注册</button>
      </div>
      <div class="registerPic">
        <img src="../../assets/image/register.jpg" alt="" /><br />
        <button @click="toShow2()">点我登录</button>
      </div>
      <div class="registerPic"><img src="" alt="" /></div>
      <div class="slideBox" v-show="true" ref="slideBox">
        <div class="loginBox" v-if="toShow">
          <LoginModel></LoginModel>
        </div>
        <div class="registerBox" v-if="!toShow">
          <RegisterModel></RegisterModel>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
// 最后说一遍我只会写选项,老子就是菜，再让我写组合要么它死要么我死
import {ref, onMounted, reactive, inject} from "vue";
import LoginModel from "@/components/loginModel.vue";
import RegisterModel from "@/components/registerModel.vue";
import { useRouter } from "vue-router";
import { useStore} from "vuex";
const router = useRouter();
const store = useStore();
const $axios = inject('$axios')
const slideBox = ref();
const toShow = ref(true)

function toShow1() {
  toShow.value = ! toShow.value;
  slideBox.value.style.left = 450 + "px";
}
function toShow2() {
  toShow.value = ! toShow.value;
  slideBox.value.style.left = 50 + "px";
}
function toBack() {
  router.push({
    name: "videoBox",
  });
}
//从vuex中获取token然后判断token是否失效，如果没有失去效果，不用登录
function checkToken(){
  let req = {token:""}
  let token  =  store.state.Token
  if (token!==""){
    req.token = token
    $axios.post("/common/checkToken",req).then((res)=>{
        if(res.data.data === true){
          router.push({
            name: "myself",
          });
        }
    })
  }
}
onMounted(() => {
  checkToken()
})
</script>

<style scoped>
.box {
  width: 100%;
  height: 100%;
  position: absolute;
  background: linear-gradient(45deg, #ff4b2b 33%, #ff416c 66%, white);
}

.back {
  width: 0px;
  height: 0px;
}

.back img {
  width: 50px;
  height: 50px;
  position: relative;
  top: 50px;
  left: 50px;
  cursor: pointer;
}

.container {
  width: 900px;
  height: 400px;
  background-color: white;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 14px;
}

.slideBox {
  width: 400px;
  height: 500px;
  background-color: rgb(233, 118, 137);
  position: absolute;
  top: -50px;
  left: 50px;
  border-radius: 14px;
  transition: left 0.3s linear;
}

.slideBox .active {
  left: 450px;
}

.loginPic {
  position: absolute;
  right: 100px;
  top: 50px;
}

.loginPic img {
  width: 200px;
  height: 200px;
}

.loginPic button {
  width: 80px;
  height: 40px;
  border: 1px solid pink;
  background-color: white;
  border-radius: 14px;
  position: absolute;
  left: 60px;
  top: 250px;
  cursor: pointer;
}

.registerPic {
  position: absolute;
  left: 100px;
  top: 50px;
}

.registerPic img {
  width: 200px;
  height: 200px;
}

.registerPic button {
  width: 80px;
  height: 40px;
  border: 1px solid pink;
  background-color: white;
  border-radius: 14px;
  position: absolute;
  left: 60px;
  top: 250px;
  cursor: pointer;
}
</style>